package com.encon.projecttracker.server.servlet;

import java.util.List;

import javax.servlet.ServletException;

import org.apache.log4j.Logger;

import com.encon.projecttracker.rpc.Query;
import com.encon.projecttracker.rpc.beans.TestDTO;
import com.encon.projecttracker.server.services.QueryService;
import com.encon.projecttracker.server.services.SessionService;
import com.encon.projecttracker.server.messages.Messages;


/**
 * 
 * Spring based query servlet.
 *
 * @author tom(at)wamonline.org.uk
 *
 */
public class QueryServlet extends AbstractServlet implements Query{
    	
    private static final long serialVersionUID = 1L;
	
	private transient QueryService queryService;
	
    private transient SessionService sessionService;

	private transient Logger log = Logger.getLogger(QueryServlet.class);
	public void init() throws ServletException {
		super.init();
		queryService = (QueryService)applicationContext.getBean("queryService"); //$NON-NLS-1$
		sessionService = (SessionService)applicationContext.getBean("sessionService"); //$NON-NLS-1$

		if (queryService==null)
		   throw new ServletException(Messages.getString("Servlet.QueryServiceNotFound")); //$NON-NLS-1$
		
		 if (sessionService==null)
	            throw new ServletException(Messages.getString("Servlet.SessionServiceNotFound")); //$NON-NLS-1$

	}
	public List<TestDTO> getRecords(String sessionId) {

	    return this.queryService.getRecords(getCurrentUserId(), sessionId);
	    }

	

}
